package com.rowline.admin.module.study.mybatiscache;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * ClassName:MySqlSessionFactory
 * Created by 245167
 * on 2018/4/28  28:44
 * description:
 */
public class MySqlSessionFactory {

    private static SqlSessionFactory sqlSessionFactory;

    static{
        System.out.println("》》》》 MySqlSessionFactory 静态代码块");
        InputStream inputStream = MySqlSessionFactory.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    public static SqlSessionFactory getSqlSessionFactory(){
        System.out.println("》》》》 MySqlSessionFactory 静态方法 getSqlSessionFactory()");
        return sqlSessionFactory;
    }

    public static SqlSession getSqlSession(){
        System.out.println("》》》》 MySqlSessionFactory 静态方法 getSqlSession()");
        return sqlSessionFactory.openSession();
    }



}
